function initMap(map_id, coordX, coordY, useGeolocation) {    
    var marker_location = new google.maps.LatLng(-34.91799473178151, -56.166508197784424);
    if (coordX.value != '' && coordY.value != '') {
        marker_location = new google.maps.LatLng(coordX.value, coordY.value);
    }
	var options = { zoom: 14, center: marker_location, mapTypeId: google.maps.MapTypeId.TERRAIN };
	var googleMap = new google.maps.Map($("#" + map_id)[0], options);
    var marker = new google.maps.Marker({ position: marker_location, map: googleMap, draggable: true, visible: true });
    
	function updateMarkerLocation() {
	    coordX.value = marker_location.lat();
	    coordY.value = marker_location.lng();
	    marker.setPosition(marker_location);
	}
	google.maps.event.addListener(marker, "dragend", function () {
	    marker_location = marker.getPosition();
	    updateMarkerLocation();
	});

	if (useGeolocation == 'True' && navigator.geolocation) {
	    navigator.geolocation.getCurrentPosition(
			function (position) {
			    marker_location = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                googleMap.setCenter(marker_location);
			    updateMarkerLocation();
			}, function () {}
		);
	}

	
	

	googleMap.setCenter(marker_location);
}

function toggleMap(map_id) {
	var map = document.getElementById(map_id);
	var show_link = document.getElementById(map_id + '_show');
	var hide_link = document.getElementById(map_id + '_hide');
	if (!map || !map.style.display || (map.style.display == 'none')) {
		show_link.style.display = 'block';
		hide_link.style.display = 'none';
	} else {
		show_link.style.display = 'none';
		hide_link.style.display = 'block';
	}
}

function toggle(map_id, idCoordX, idCoordY, useGeolocation) {
	var map = document.getElementById(map_id);
	if (map.style.width == 0) {
		map.style.width = '100%';
		map.style.height = $(map).parent().width() + "px";
		map.style.display = 'block';
		initMap(map_id, document.getElementById(idCoordX), document.getElementById(idCoordY), useGeolocation);
	} else if (map.style.display == 'none') {
		map.style.display = 'block';
	} else {
		map.style.display = 'none';
	}
	toggleMap(map_id);
}